package com.WebMentorPro.system.service.impl;

import com.WebMentorPro.system.common.ErrorCode;
import com.WebMentorPro.system.exception.BusinessException;
import com.WebMentorPro.system.mapper.BookBorrowMapper;
import com.WebMentorPro.system.model.dto.bookBorrow.BorrowQueryRequest;
import com.WebMentorPro.system.model.dto.expertReading.ExpertQueryRequest;
import com.WebMentorPro.system.model.entity.BookBorrow;
import com.WebMentorPro.system.model.vo.BookBorrowVO;
import com.WebMentorPro.system.service.BookBorrowService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author bianxiaoyao
* @description 针对表【book_borrow(书籍借阅表)】的数据库操作Service实现
* @createDate 2024-11-24 11:24:42
*/
@Service
public class BookBorrowServiceImpl extends ServiceImpl<BookBorrowMapper, BookBorrow>
    implements BookBorrowService {

    @Resource
    private BookBorrowMapper bookBorrowMapper;

    @Override
    public Page<BookBorrowVO> getQueryWrapper(Page<BookBorrowVO> pageParam, BorrowQueryRequest borrowQueryRequest) {
        // 自定义分页查询
        List<BookBorrowVO> bookBorrowVOS = bookBorrowMapper.getQuery(pageParam, borrowQueryRequest);
        if (bookBorrowVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(bookBorrowVOS);
        return pageParam;
    }

    @Override
    public Page<BookBorrowVO> getQueryByStudent(Page<BookBorrowVO> pageParam, BorrowQueryRequest borrowQueryRequest, Long userId) {
        // 自定义分页查询
        List<BookBorrowVO> bookBorrowVOS = bookBorrowMapper.getQueryByStudent(pageParam, borrowQueryRequest, userId);
        if (bookBorrowVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(bookBorrowVOS);
        return pageParam;
    }

    @Override
    public Page<BookBorrowVO> getQueryByMyStudent(Page<BookBorrowVO> pageParam, BorrowQueryRequest borrowQueryRequest, Long teacherId) {
        // 自定义分页查询
        List<BookBorrowVO> bookBorrowVOS = bookBorrowMapper.getQueryByMyStudent(pageParam, borrowQueryRequest, teacherId);
        if (bookBorrowVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(bookBorrowVOS);
        return pageParam;
    }
}




